<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件绑定基本使用</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: orange;
    }
    .box2 {
      width: 100px;
      height: 100px;
      background-color: red;
    }
    .box3 {
      width: 100px;
      height: 100px;
      background-color: green;
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    <!--1. 基本写法-->
    <div class="box" v-on:click="divClick">基本写法</div>
    <!--2. 语法糖写法(重点)-->
    <div class="box2" @click="divClickSymbol">语法糖</div>
    <!--3. 绑定的方法位置, 也可以写成一个表达式(不常用, 不推荐)-->
    <h2> {{counter}} </h2>
    <button @click="increament">+1</button>
    <button @click="counter++">+1</button>
    <!--4. 绑定其他方法(重点)-->
    <div class="box3" @mousemove="divMouseMove">鼠标移动</div>
    <!--5. 绑定多个事件-->
    <div class="box3" @click="divClickSymbol" @mousemove="divMouseMove">绑定多个事件</div>
    <!--6. 对象语法(不常用, 不推荐)-->
    <div class="box3" v-on="{click: divClick, mousemove: divMouseMove}">对象语法</div> 
    <div class="box3" @="{click: divClick, mousemove: divMouseMove}">对象语法加语法糖</div> 
  </div>
  <script src="../lib/vue.js"></script>
  <script>
    // 使用vue
    const app = Vue.createApp({
      data: function(){
        return {
          message: "hello v-on"
          , counter: 0
        }
      }
      ,methods: {
        divClick: function() {
          console.log("基本写法")
        }
        ,divClickSymbol() {
          console.log("语法糖")
        }
        , increament() {
          this.counter++
        }
        , divMouseMove() {
          console.log("mouseover")
        }
      }
    }
    )
    // 挂载 
    app.mount("#app")
  </script>

</body>
</html>
